package com.demo.house.service.impl;

import com.demo.house.dao.UserDao;
import com.demo.house.entity.User;
import com.demo.house.service.UserService;
import com.demo.house.vo.RequestVo.LoginVo;
import com.demo.house.vo.request.RequestMessageVo;
import com.demo.house.vo.request.RequestRegisteredVo;
import com.demo.house.vo.request.RequestUserVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author zhushubiao
 * @title: UserService
 * @projectName House
 * @description: TODO
 * @date 2021/3/16 14:48
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;

    /**
     * 根据id修改
     * @param id
     * @return
     */
    @Override
    public User getById(Integer id) {
        User user = userDao.selectByPrimaryKey(id);
        return user;
    }

    /**
     * 根据id删除
     * @param id
     * @return
     */
    @Override
    public RequestUserVo deleteByid(Integer id) {
        int i = userDao.deleteByPrimaryKey(id);
        RequestUserVo vo=new RequestUserVo();
        BeanUtils.copyProperties(i,vo);
        return vo;
    }

    /**
     * 注册功能
     * @param requestRegisteredVo
     * @return
     */
    @Override
    public int register(RequestRegisteredVo requestRegisteredVo) {
        User user=new User();
        BeanUtils.copyProperties(requestRegisteredVo,user);
        return userDao.insertSelective(user);

    }


    /**
     * 根据id查询修改
     * @param requestUserVo
     * @return
     */
    @Override
    public User updateByid(RequestUserVo requestUserVo) {
        return userDao.selectByPrimaryKey(requestUserVo.getId());
    }

    /**
     * 修改
     * @param user
     * @return
     */
    @Override
    public int update(User user) {
        return userDao.updateByPrimaryKey(user);
    }

    @Override
    public int updateByPrimaryKeySelective(User user) {
        return userDao.updateByPrimaryKeySelective(user);
    }

    @Override
    public User getUsername(String username) {
        return userDao.getUsername(username);

    }

    @Override
    public User login(LoginVo loginVo) {
        return userDao.login(loginVo);
    }

/*    @Override
    public User selectNameAndTelephone(Integer id) {
        return userDao.selectNameAndTelephone(id);
    }*/


}
